package 类和对象课堂练习.异常;
//3:老师有年龄，学校，姓名的属性，有上课和自我介绍的方法，如果年龄少于22岁，抛出异常。
public class Zuoye04062 {
    private String name;
    protected int age;
    private String xuexiao;

    public Zuoye04062(String name, String xuexiao) {
        this.name = name;
        this.xuexiao = xuexiao;
    }
    public void shangke(){
        System.out.println(name+"老师开始上课了");
    }
    public void jieshao(){
        System.out.println("大家好我叫"+name+",是java老师，今年"+age+"岁，在"+xuexiao+"上课");

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws Exception{
        if (age>=22)
            this.age = age;
        else {
            throw new Exception("年龄必须大于22岁");
        }
    }

    public String getXuexiao() {
        return xuexiao;
    }

    public void setXuexiao(String xuexiao) {
        this.xuexiao = xuexiao;
    }
}
